define(function () {
    'use strict';

    function ctrl($scope,$state,$timeout, $ionicLoading,LocalCacheService, CommonService,FinancingService) {
        function init() {
            $scope.user = LocalCacheService.getUser();
            $scope.repaymentList = [];
            $scope.sharesList = [{
                id: '1',
                name: '中国联通 600060',
                pledgeStatus: 1,
                count: 125000,
                price: 125.00,
                marketValue: 10000.00,
                rate: 60
            }, {
                id: '2',
                name: '中国联通 600060',
                pledgeStatus: 2,
                count: 125000,
                price: 125.00,
                marketValue: 10000.00,
                rate: 60
            }]


            var params = {client_id: '66127189',title_id:'repayment'};
            $ionicLoading.show();
            FinancingService.getRepaymentIndexInfo(params).then(function (data) {
                $ionicLoading.hide();
                if (data.error_no== '0') {
                    if(data.borrowBillList.length>0){
                        for (var i = 0; i < data.borrowBillList.length; i++) {
                            var borrowBill = data.borrowBillList[i];
                            $scope.repaymentList[i].id=i;
                            $scope.repaymentList[i].money=borrowBill.back_balance;
                            $scope.repaymentList[i].day='';
                            $scope.repaymentList[i].billStart=borrowBill.entrust_date;
                            $scope.repaymentList[i].billEnd=borrowBill.back_date;
                            $scope.repaymentList[i].rate=borrowBill.profit;
                            $scope.repaymentList[i].pay=borrowBill.profit;
                        }
                    }
                }
            });
        }

        $scope.change = function (index) {
            var id = $scope.repaymentList[index].id;
            //根据id获取股票列表并修改$scope.sharesList
        };

        $scope.show = function () {
            $ionicPopup.show({
                cssClass: "kDialog",
                template: "履约比例低于170%与150%您会收到通知，当履约比率触达130%时将实行平仓，请注意查收信息并适时补充质押。",
                buttons: [
                    {text: '我知道了'}
                ]
            });
        };

        $scope.$on('$ionicView.loaded', function () {
            init();
            $timeout(function(){
                $("#featureCarousel").featureCarousel({
                    largeFeatureWidth: 0.45,
                    largeFeatureHeight: 0.5,
                    smallFeatureWidth: 0.2,
                    smallFeatureHeight: 0.2,

                    sidePadding:-50
                });
            },1000);
        });
    }

    ctrl.$inject = ['$scope', '$state', '$timeout',  '$ionicLoading', 'LocalCacheService', 'CommonService', 'FinancingService'];
    return ctrl;
});